import {MissonModel} from '../Misson/missonModel'

/* 定义Transport角色相关任务 */
export default class RoomTaskTransport extends Room {
    /* 虫卵填充任务监控 */
    public FTE_PAS():void{
        if (Game.time % 11) return
        if (!this.memory.TaskMemory.storageID) return
        if (this.CheckInMisson('CREEP','虫卵填充')) return
        var disExtensions = this.find(FIND_MY_STRUCTURES,{filter:(structure)=>{
            return (structure.structureType == 'spawn' || structure.structureType == 'extension') && structure.store.getFreeCapacity('energy') > 0
        }})
        if (disExtensions.length <= 0) return
        let thisTask:RoomTask = {} as RoomTask
        Object.assign(thisTask,MissonModel['虫卵填充'])
        thisTask.relateCreep = ['transport01']
        this.mountMisson(thisTask)
    }
    /* 远塔填充任务监控 */
    public SToFT_PAS():void{
        if (Game.time % 17) return
        if (!this.memory.TaskMemory.OtowerID) return
        if (this.CheckInMisson('CREEP','远塔填充')) return
        LoopF:
        for (var i of this.memory.TaskMemory.OtowerID)
        {
            var tower_ = Game.getObjectById(i) as StructureTower
            if (!tower_)
            {
                var index = this.memory.OtowerID.indexOf(i)
                this.memory.OtowerID.splice(index,1)
                continue LoopF
            }
            if (tower_.store.getFreeCapacity('energy') > 200)
            {
                /* 如果存在，就挂载任务 */
                let thisTask:RoomTask = {} as RoomTask
                Object.assign(thisTask,MissonModel['远塔填充'])
                thisTask.relateCreep = ['transport01']
                this.mountMisson(thisTask)
                return
            }
        }
    }
    /* 实能填充任务监控 */
    public FTLE_PAS():void{
        if (Game.time % 9) return
        if (!this.memory.TaskMemory.labs) return
        if (this.CheckInMisson('CREEP','物流搬运')) return
        LoopLabs:
        for (var labID of this.memory.TaskMemory.labs)
        {
            var thisLab = Game.getObjectById(labID) as StructureLab
            /* 找不到就删除 */
            if (!thisLab)
            {
                var index = this.memory.TaskMemory.labs.indexOf(labID)
                this.memory.labs.splice(index,1)
                continue LoopLabs
            }
            if (thisLab.store['energy'] < 1500)
            {
                var storage_ = Game.getObjectById(this.memory.TaskMemory.storageID as string) as StructureStorage
                if (storage_ && storage_.store['energy'] > 1000)
                {
                    let thisTask:RoomTask = {} as RoomTask
                    Object.assign(thisTask,MissonModel['物流搬运'])
                    thisTask.relateCreep = ['transport01']
                    thisTask.disnum = 2000
                    thisTask.relateResource = ['energy']
                    thisTask.disStructure = [labID]
                    thisTask.sourceStructure = [this.memory.TaskMemory.storageID as string]
                    this.mountMisson(thisTask)
                    return
                }
            }
        }
    }

    /* 核弹填充任务主动处理 */

}